package dataserver.controller;

import dataserver.api.IesLabApi;
import dataserver.api.IesLabResponseInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * @author lrz
 */
@Controller
@CrossOrigin
@RequestMapping("/interfaceData")
@Tag(name = "宁夏积成相关-查询在线监测数据")
public class IseLabController extends BaseController {
    private static final Logger logger = LogManager.getLogger(IseLabController.class);

    @Autowired
    IesLabApi iesLabApi;

    /**
     * 查询在线监测数据-变压器光声光谱
     *
     * @param stationCode
     * @param equipmentId
     * @throws Exception
     */
    @Operation(summary = "变压器光声光谱")
    @GetMapping(value = "/getOnlineMonitorInfoTransForm")
    public void getOnlineMonitorInfoTransForm(HttpServletResponse response,
                                 @RequestParam(required = false) String stationCode,
                                 @RequestParam(required = false) String equipmentId) throws Exception {
        try {
            String url = "/interfaceData/getOnlineMonitorInfoTransForm";
            IesLabResponseInfo successInfo = iesLabApi.getOnlineMonitorInfoTransForm(stationCode, equipmentId, "TransForm", url);
            String targetData = toJson(successInfo);
            returnCollection(response, targetData);
        } catch (Exception e) {
            returnCollection(response, e);
        }
    }
    /**
     * 变查询在线监测数据-铁芯电流
     *
     * @param stationCode
     * @param equipmentId
     * @throws Exception
     */
    @Operation(summary = "铁芯电流")
    @GetMapping(value = "/getOnlineMonitorInfoCoreCurrent")
    public void getOnlineMonitorInfoCoreCurrent(HttpServletResponse response,
                                 @RequestParam(required = false) String stationCode,
                                 @RequestParam(required = false) String equipmentId) throws Exception {
        try {
            String url ="/interfaceData/getOnlineMonitorInfoCoreCurrent";
            IesLabResponseInfo successInfo = iesLabApi.getOnlineMonitorInfo(stationCode,equipmentId, "CoreCurrent",url);
            String targetData = toJson(successInfo);
            returnCollection(response, targetData);
        } catch (Exception e) {
            returnCollection(response, e);
        }
    }
    /**
     * 查询在线监测数据-避雷器
     *
     * @param stationCode
     * @param equipmentId
     * @throws Exception
     */
    @Operation(summary = "避雷器")
    @GetMapping(value = "/getOnlineMonitorInfoArrester")
    public void getOnlineMonitorInfoArrester(HttpServletResponse response,
                                 @RequestParam(required = false) String stationCode,
                                 @RequestParam(required = false) String equipmentId) throws Exception {
        try {
            String url = "/interfaceData/getOnlineMonitorInfoArrester";
            IesLabResponseInfo successInfo = iesLabApi.getOnlineMonitorInfo(stationCode,equipmentId,"Arrester", url);
            String targetData = toJson(successInfo);
            returnCollection(response, targetData);
        } catch (Exception e) {
            returnCollection(response, e);
        }
    }
    /**
     * 查询在线监测数据-特高频局放
     *
     * @param stationCode
     * @param equipmentId
     * @throws Exception
     */
    @Operation(summary = "特高频局放")
    @GetMapping(value = "/getOnlineMonitorInfoPartialDischarge")
    public void getOnlineMonitorInfoPartialDischarge(HttpServletResponse response,
                                 @RequestParam(required = false) String stationCode,
                                 @RequestParam(required = false) String equipmentId) throws Exception {
        try {
            String url =  "/interfaceData/getOnlineMonitorInfoPartialDischarge";
            IesLabResponseInfo successInfo = iesLabApi.getOnlineMonitorInfo3(stationCode,equipmentId,"PartialDischarge", url);
            String targetData = toJson(successInfo);
            returnCollection(response, targetData);
        } catch (Exception e) {
            returnCollection(response, e);
        }
    }
    /**
     * 查询在线监测数据-变压器和电缆
     *
     * @param stationCode
     * @param equipmentId
     * @throws Exception
     */
    @Operation(summary = "变压器和电缆")
    @GetMapping(value = "/getOnlineMonitorInfoTransformerCable")
    public void getOnlineMonitorInfoTransformerCable(HttpServletResponse response,
                                 @RequestParam(required = false) String stationCode,
                                 @RequestParam(required = false) String equipmentId) throws Exception {
        try {
            String url =  "/interfaceData/getOnlineMonitorInfoTransformerCable";
            IesLabResponseInfo successInfo = iesLabApi.getOnlineMonitorInfo3(stationCode,equipmentId,"TransformerCable", url);
            String targetData = toJson(successInfo);
            returnCollection(response, targetData);
        } catch (Exception e) {
            returnCollection(response, e);
        }
    }
    /**
     * 查询在线监测数据-密度微水
     *
     * @param stationCode
     * @param equipmentId
     * @throws Exception
     */
    @Operation(summary = "密度微水")
    @GetMapping(value = "/getOnlineMonitorInfoDensityMoisture")
    public void getOnlineMonitorInfoDensityMoisture(HttpServletResponse response,
                                 @RequestParam(required = false) String stationCode,
                                 @RequestParam(required = false) String equipmentId) throws Exception {
        try {
            String url = "/interfaceData/getOnlineMonitorInfoDensityMoisture";
            IesLabResponseInfo successInfo = iesLabApi.getOnlineMonitorInfo3(stationCode,equipmentId,"Mico", url);
            String targetData = toJson(successInfo);
            returnCollection(response, targetData);
        } catch (Exception e) {
            returnCollection(response, e);
        }
    }
}
